//
//  SinaWelcomeViewController.m
//  MySinaWeiboProjectForOC
//
//  Created by apple on 2016/11/17.
//  Copyright © 2016年 WangChen. All rights reserved.
//

#import "SinaWelcomeViewController.h"
#import <Masonry.h>
#import <UIImageView+WebCache.h>
#import "SinaUserAccountViewModel.h"

@interface SinaWelcomeViewController ()
@property (nonatomic,weak) UIImageView *iconIV;
@property (nonatomic,weak) UILabel *welcomLbl;
@end

@implementation SinaWelcomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self setupUI];
}


//动画放在这里做
-(void)viewDidAppear:(BOOL)animated{
    
    //动画
    [UIView animateWithDuration:1.5 delay:0 usingSpringWithDamping:0.3 initialSpringVelocity:5 options:0 animations:^{
        
        [_iconIV mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(self.view).offset(-(kScreenHeight - 180 - 85));
        }];
        [self.view layoutIfNeeded];
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:0.5 animations:^{
            _welcomLbl.alpha = 1;
        }completion:^(BOOL finished) {
            //发送通知,切换到tabBarVC
            [[NSNotificationCenter defaultCenter]postNotificationName:kNotificationChangeVC object:kNotificationToTabBarVC];
        }];
    }];

    
}



#pragma mark
#pragma mark - 布局界面
-(void)setupUI{
    
    //头像
    UIImageView *iconIV = [[UIImageView alloc]init];
    [self.view addSubview:iconIV];
    _iconIV = iconIV;
    iconIV.layer.cornerRadius = 42.5;
    iconIV.layer.masksToBounds = YES;
    
    //lable
    UILabel *welComeLbl = [[UILabel alloc]init];
    welComeLbl.text = @"欢迎回来";
    welComeLbl.font = [UIFont systemFontOfSize:18];
    welComeLbl.textColor = [UIColor darkGrayColor];
    welComeLbl.alpha = 0;
    _welcomLbl = welComeLbl;
    [self.view addSubview:welComeLbl];
    
    
    [iconIV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.bottom.equalTo(self.view).offset(-180);
        make.size.mas_equalTo(CGSizeMake(85, 85));
    }];
    
    [iconIV sd_setImageWithURL:[SinaUserAccountViewModel shared].iconURL placeholderImage:[UIImage imageNamed:@"avatar_default"]];
    
    
    [welComeLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(iconIV);
        make.top.equalTo(iconIV.mas_bottom).offset(20);
    }];
    
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
